﻿using System;
using System.Runtime.InteropServices;

// SkypeScreenSaver, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace SkypeScreenSaver
{
    public class MonitorOnOff
    {
        //
        const int SC_MONITORPOWER = 0xF170;
        const int WM_SYSCOMMAND = 0x0112;
        //
        const int MONITOR_ON = -1;
        const int MONITOR_OFF = 2;
        const int MONITOR_STANBY = 1;
        //
        [DllImport("user32.dll")]
        static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, int lParam);
        //
        public static bool Set(IntPtr hWnd, bool beOn)
        {
            //
            if (beOn)
            {
                SendMessage(hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);
            }
            else
            {
                SendMessage(hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
            }
            //
            return true;
        }
        //
    }//class
}//namespace
